<div id="edit-book-form-ctr">
	<form action="editbook.php?id=<?php echo $this->book->id; ?>" 
		id="edit-book-form" 
		method="post" 
		x:failed="alert" 
		x:done="save_author">
		<label for="title">Title:</label>
		<br />
		<input type="text" name="title" id="title" 
			value="<?php echo $this->escape($this->book->title); ?>" />
		<br />
		<br />
		<label>Author(s):</label>
		<br />
		<select id="author">
		<?php foreach ($this->author_list as $author) : ?>
			<option value="<?php echo $author->id; ?>"><?php echo $this->escape($author->name); ?></option>
		<?php endforeach; ?>
		</select>
		<input type="button" onclick="add_author();" value="+" />
		<br />
		<br />
		<div id="author-list">
		<?php foreach ($this->book->getAuthors() as $author) : ?>
			<div>
				<input type="button" onclick="remove_author(this.parentNode)" value="&times;" />
				<input type="hidden" name="author[]" value="<?php echo $author->id; ?>" />
				<?php echo $this->escape($author->name); ?>
			</div>
		<?php endforeach; ?>
		</div>
		
		<br />
		<br />
		<input type="submit" value="Save" />
		<input type="reset" value="Cancel" onclick="$.Agrid.activeInstance.dialog.dialog('close');" />
	</form>
</div>
<script type="text/javascript">
Morf.run('edit-book-form');
function add_author() {
	var s = $('#author').get(0);
	var id = s.value;
	var name = s.options[s.options.selectedIndex].text;
	$('#author-list').append($('<div>'+
		'<input type="button" onclick="remove_author(this.parentNode)" value="&times;" />' +
		'<input type="hidden" name="author[]" value="'+id+'" />' + name + 
	'</div>'));
}
function remove_author(node) {
	node.parentNode.removeChild(node);
}
function save_author(data) {
	$.Agrid.activeInstance.closeEditor(data);
}
</script>